//
//  WBNavigationController.swift
//  新浪微博
//
//  Created by ZTE on 2017/12/1.
//  Copyright © 2017年 ZTE. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {


    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        //隐藏系统的 navigationBar
       
        
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //如果不是栈底控制器才需要隐藏，根控制器不需要隐藏
        if childViewControllers.count>0 {
            //隐藏底部的 tabbar
            viewController.hidesBottomBarWhenPushed = true
            //判断控制器的类型
            if let vc = viewController as? WBBaseViewController {
                
                var title = "返回"
                //判断控制器的级数
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(popToParent), isBack: true)
                
            }
        }
  
        super.pushViewController(viewController, animated: true)
        
    }
    
    //pop 返回到上一级控制器
    @objc private func popToParent() {
        
        popViewController(animated: true)
    }
    


}
